home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / Erics C++ Libraries / Interface Classes / CPPDialogText.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  3.0 KB  |  114 lines  |  [TEXT/KAHL]

  1. /********************************************************* DEFINITION
  2.     DATE:    9/28/93
  3.     AUTHOR: Eric R. Rosé
  4.     
  5.     CLASS:  CPPDialogText
  6.     
  7.     SUPERCLASS: CPPFilterText
  8.     
  9.         This C++ class manages a textedit area with no scrollbars and
  10.         a length limit of 255 characters.
  11.     
  12. ********************************************************************/
  13.  
  14. #include <CPPDialogText.h>
  15.  
  16. /*-----------------------------------------------------------------*/
  17. /*------------------------ PUBLIC METHODS -------------------------*/
  18. /*-----------------------------------------------------------------*/
  19.  
  20.     CPPDialogText::CPPDialogText (CPPWindow *OurWindow,
  21.                                    Rect *itsBounds,
  22.                                    StringPtr defaultString,
  23.                                    int maxLength,
  24.                                    int Font,
  25.                                    int FSize) :
  26.                    CPPFilterText (OurWindow, itsBounds, itsBounds,
  27.                                      maxLength, block, (int)none, FALSE,
  28.                                      FALSE, Font, FSize)
  29.     {
  30.         if (defaultString)
  31.           SetToString (defaultString);
  32.           
  33.         SetFilterString ("\p\r");    // no returns allowed
  34.     }
  35.  
  36. /*-----------------------------------------------------------------*/
  37.  
  38.     CPPDialogText::CPPDialogText (CPPWindow *OurWindow,
  39.                                    Rect *itsBounds,
  40.                                    short StringID,
  41.                                    int maxLength,
  42.                                    int Font,
  43.                                    int FSize) :
  44.                    CPPFilterText (OurWindow, itsBounds, itsBounds,
  45.                                      maxLength, pass, (int)all, FALSE,
  46.                                      FALSE, Font, FSize)
  47.     {
  48.         StringHandle    tempString = GetString (StringID);
  49.         
  50.         if (tempString)
  51.           {
  52.             SetTextHandle((Handle)tempString, 
  53.                             GetHandleSize((Handle)tempString),
  54.                             TRUE);
  55.              ReleaseResource((Handle)tempString);
  56.           }
  57.     }
  58.  
  59. /*-----------------------------------------------------------------*/
  60.  
  61.     CPPDialogText::~CPPDialogText (void)
  62.     {    
  63.     }
  64.     
  65. /*-----------------------------------------------------------------*/
  66.  
  67.     char    *CPPDialogText::ClassName (void)
  68.     {
  69.         return "CPPDialogText";
  70.     }
  71.  
  72. /*-----------------------------------------------------------------*/
  73.  
  74.     void    CPPDialogText::TargetHilite (Boolean makeTarget)
  75.     /* change the hiliteed state of the object */
  76.     /* if the text object is becoming the target, select all its text */
  77.     {
  78.         CPPFilterText::TargetHilite(makeTarget);
  79.         
  80.         if (this->IsActive())
  81.           DoSelectAll();
  82.     }
  83.  
  84. /*-----------------------------------------------------------------*/
  85.  
  86.     StringPtr    CPPDialogText::GetAsString (void)
  87.     /* allocate and return as a stringptr a copy of the text */
  88.     /* in the text edit area */
  89.     {
  90.         CharsHandle    tempHandle = GetTheText();
  91.         short        textLen = GetHandleSize(tempHandle);
  92.         StringPtr    tempPtr;
  93.         
  94.         if (tempHandle && textLen)
  95.           {
  96.               tempPtr = (StringPtr)NewPtr(textLen + 1);
  97.               if (tempPtr)
  98.                 {
  99.                   BlockMove (*tempHandle, tempPtr+1, textLen);
  100.                   *tempPtr = textLen;
  101.                 }
  102.           }    
  103.         return tempPtr;
  104.     }
  105.  
  106. /*-----------------------------------------------------------------*/
  107.  
  108.     void    CPPDialogText::SetToString (StringPtr newString)
  109.     /* set the dialog text object's contents to the passed-in string */
  110.     {
  111.         if (newString)
  112.           SetTextPtr ((Ptr)(newString+1), *newString, TRUE);
  113.     }
  114.